package com.xn.app.muying.adpter;

import android.content.Context;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.xn.app.muying.R;
import com.xn.app.muying.bean.DoctorGsonBean;
import com.xn.app.muying.util.HttpUtil;

import java.util.ArrayList;

/**
 * Created by Administrator on 2016/11/1.
 */
public class DoctorLeftAdapter extends BaseAdapter {
    private LayoutInflater inflater;
    private Context context;
    private ArrayList<DoctorGsonBean.SubCompaniesBean> list = new ArrayList();
    private Handler handler = new Handler();
    private int sign = 0;
    private ImageLoader imageLoader;
    private DisplayImageOptions options;

    public DoctorLeftAdapter(Context context, Handler handler, ImageLoader imageLoader, DisplayImageOptions options) {
        this.context = context;
        this.handler = handler;
        this.imageLoader = imageLoader;
        this.options=options;
        inflater = LayoutInflater.from(context);
    }

    public void getData(ArrayList<DoctorGsonBean.SubCompaniesBean> data) {
        this.list.clear();
        this.list.addAll(data);
        notifyDataSetChanged();
    }

    //获取当前点击item的position
    public void getSign(int sign) {
        this.sign = sign;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder = null;
        if (view == null) {
            view = inflater.inflate(R.layout.doctorleftlistview, null);
            holder = new ViewHolder();
            holder.iv = (ImageView) view.findViewById(R.id.doctorleft_iv);
            holder.tv = (TextView) view.findViewById(R.id.doctorleft_tv);
            holder.fl = (FrameLayout) view.findViewById(R.id.doctorleft_ll);
            holder.imageview = (ImageView) view.findViewById(R.id.doctorleft_imageview);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }

        holder.tv.setText(list.get(i).getName());
        holder.iv.setTag(list.get(i).getLogo());
//        HttpUtil.getBitMap(list.get(i).getLogo().toString(), handler, holder.iv);
        //设置图片，如果内存中有，优先从内存中读取
        if (list.get(i).getLogo() != null && !list.get(i).getLogo().toString().equals("") && !list.get(i).getLogo().toString().equals("null")) {
            imageLoader.displayImage(list.get(i).getLogo().toString(), holder.iv, options);
        }
        if (sign == i) {
            holder.tv.setTextColor(context.getResources().getColor(R.color.black));
            holder.fl.setBackgroundResource(R.color.education_state_list_bjcolor);
            holder.imageview.setVisibility(ImageView.VISIBLE);
        } else {
            holder.tv.setTextColor(context.getResources().getColor(R.color.education_state_list_color));
            holder.fl.setBackgroundResource(R.color.bj_color);
            holder.imageview.setVisibility(ImageView.GONE);
        }

        return view;
    }

    class ViewHolder {
        ImageView iv, imageview;
        TextView tv;
        FrameLayout fl;
    }


}

